package net;

import java.io.IOException;
import java.net.InetAddress;
import java.net.URL;

/**
 * @projectName: java-sample
 * @description:
 * @author: Adam
 * @create: 2020-01-05 15:24
 **/

public class IentAddressTest {
    public static void main(String[] args) throws IOException {

        //根据主机获取对应的 InetAddress 对象
        InetAddress ip = InetAddress.getByName("www.baidu.com");
        System.out.println(ip.toString());
        //判断是否可达
        System.out.println("是否可达:"+ip.isReachable(2000));
        //获取实例的ip字符串
        System.out.println(ip.getHostAddress());
        //根据原始ip地址来获取对应的InetAddress实例
        InetAddress local = InetAddress.getByAddress(new byte[]{(byte)180,101,49,11});
        System.out.println(local.isReachable(5000));
        //权限的域名
        String region = local.getCanonicalHostName();
        System.out.println("域名:"+local.getCanonicalHostName());
    }
}
